package com.enjoyor.soa.traffic.server.efoms.dubbo.manage;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSONArray;
import com.enjoyor.filter.SSOClientfilter;
import com.enjoyor.soa.traffic.api.dto.efoms.CheckRecodeInfoDto;
import com.enjoyor.soa.traffic.api.uums.dto.UserDto;
import com.enjoyor.soa.traffic.core.efoms.domain.AssentFileInfo;
import com.enjoyor.soa.traffic.core.efoms.domain.CheckRecodeInfo;
import com.enjoyor.soa.traffic.core.efoms.service.ICheckRecordInfoService;
import com.enjoyor.soa.traffic.server.efoms.dubbo.listener.MessagePushClient;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.helper.ResultHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Service(timeout = 6000)
public class ManageCheckRecordInfoService {

	@Autowired
	private ICheckRecordInfoService iCheckRecordInfoService;
	
	@Autowired
	private MessagePushClient messagePushClient;
	
	public ResultPojo getCheckRecordInfo(String CheckRecordInfoId) {
		CheckRecodeInfo checkRecodeInfo = iCheckRecordInfoService.getCheckRecordInfo(CheckRecordInfoId);
		return ResultHelper.getResult(ReflectHelper.beanToBean(checkRecodeInfo, CheckRecodeInfoDto.class));
	}

	public ResultPojo getCheckRecodeInfoList(String CheckRecordInfoId,String devId,String checkPersonCode,String startTime,String endTime,String devAreaCode,String devAreaName,String checkPersonName,String devCategoryCode,String devTypeCode,String checkResultCode) {
		List<CheckRecodeInfo> list = iCheckRecordInfoService.getCheckRecodeInfoList(CheckRecordInfoId,devId,checkPersonCode,startTime,endTime,devAreaCode,devAreaName,checkPersonName,devCategoryCode,devTypeCode,checkResultCode);
		return ResultHelper.getResult(ReflectHelper.listToList(list, CheckRecodeInfoDto.class));
	}

	public ResultPojo getCheckRecordInfoPage(String CheckRecordInfoId,String devId,String checkPersonCode,String startTime,String endTime,String devAreaCode,String devAreaName,String checkPersonName,String devCategoryCode,String devTypeCode,String checkResultCode,String devName,Page page) {
		return ResultHelper.getResult(iCheckRecordInfoService.getCheckRecordInfoPage(CheckRecordInfoId,devId,checkPersonCode,startTime,endTime,devAreaCode,devAreaName,checkPersonName,devCategoryCode,devTypeCode,checkResultCode,devName,page));
	}

	public ResultPojo insertCheckRecordInfo(String list, UserDto userDto) {
		List<CheckRecodeInfo> CheckRecodeInfoDtoList = JSONArray.parseArray(list, CheckRecodeInfo.class);
		for(int i = 0;i<CheckRecodeInfoDtoList.size();i++){
			CheckRecodeInfoDtoList.get(i).setCheckDeptCode(userDto.getOrgId());
			CheckRecodeInfoDtoList.get(i).setCheckDeptName(userDto.getOrgName());
			CheckRecodeInfoDtoList.get(i).setCheckPersonCode(userDto.getPersonId());
			CheckRecodeInfoDtoList.get(i).setCheckPersonName(userDto.getPersonName());
		}
		ResultPojo resultPojo = iCheckRecordInfoService.insertCheckRecordInfo(CheckRecodeInfoDtoList, userDto.getPersonName());
		messagePushClient.getCheckPushNumList(CheckRecodeInfoDtoList.get(0).getDevTypeCode());
		return resultPojo;
	}

	public ResultPojo updateCheckRecordInfo(CheckRecodeInfoDto checkRecodeInfoDto, String userName) {
		CheckRecodeInfo checkRecodeInfo = ReflectHelper.beanToBean(checkRecodeInfoDto, CheckRecodeInfo.class);
		ResultPojo resultPojo = iCheckRecordInfoService.updateCheckRecordInfo(checkRecodeInfo, userName);
		return resultPojo;
	}

	public ResultPojo delCheckRecordInfo(String CheckRecordInfoId, String userName) {
		ResultPojo resultPojo = iCheckRecordInfoService.delCheckRecordInfo(CheckRecordInfoId, userName);
		return resultPojo;
	}
}
